package org.meb.speedway.process.sf;

import java.util.ArrayList;
import java.util.List;

import org.meb.speedway.process.model.EventData;

public class SFEventParserChain implements SFEventParser {

	private List<SFEventParser> parsers;

	public SFEventParserChain() {
		parsers = new ArrayList<SFEventParser>();
		parsers.add(new SFLeagueEventParserV1());
	}

	public EventData parse(String eventSource) throws EventParseException {
		for (SFEventParser parser : parsers) {
			try {
				EventData eventData = parser.parse(eventSource);
				if (eventData != null) {
					return eventData;
				}
				// no problem - go to next parser
			} catch (EventParseException e) {
				e.printStackTrace();
				// no problem - go to next parser
			}
		}
		throw new EventParseException("Unable to parse event source: no suitable parser");
	}
}
